import {Component, OnInit} from '@angular/core';
import {AlertComponent} from "../../unit/alert";
import {ActivatedRoute} from "@angular/router";
import {BasicService} from "../../unit/basic-service";
import {UserInfo} from "../../modals/basic.modal";

@Component({
    selector: 'app-code-info',
    templateUrl: './code-info.page.html',
    styleUrls: ['../certificate-detail/certificate-detail.page.scss', './code-info.page.scss'],
})
export class CodeInfoPage implements OnInit {
    codeData: UserInfo;
    currentUrl: string;
    isShowClose: boolean;

    constructor(private alertComponent: AlertComponent,
                private activateInfo: ActivatedRoute,
                private basicService: BasicService) {
    }

    ngOnInit() {
        this.activateInfo.queryParamMap.subscribe((res: any) => {
            if (res?.params && res.params?.idCard) {
                this.initData(res.params);
            }
        });
    }

    initData(params) {
        this.currentUrl = params.urlType ? 'yh/getyhxq' : 'yh/get'; // yh/get no token
        this.isShowClose = !params.urlType; // search list show go back icon
        this.getInfo(params.idCard);
    }

    getInfo(idCard) {
        this.basicService.getData(this.currentUrl, {idCard}).subscribe(res => {
            this.codeData = res;
        });
    }
}
